/*
 * Serum
 *
 * @license      GNU Lesser General Public Licence see LICENCE-LGPL file or http://www.gnu.org/licenses/lgpl.html
 */

Serum.Panel.Module.List = function(config, viewer) {
    Ext.apply(this, config);
    this.viewer = viewer;

    this.listClass  = Serum.Selector.get().currentModule().listClass();

    this.list       = function() {
        return this.lists[this.listClass];
    };

    this.list           = eval('new ' + this.listClass + '(this)');

    this.title          = __(Serum.Selector.get().module.toLowerCase() + '~list_title', 'base~list_title');
    this.id             = 'list-view';

    Serum.Panel.Module.List.superclass.constructor.call(this, Ext.apply({
        id:             this.id,
        title:          __(Serum.Selector.get().module.toLowerCase() + '~list_title', 'base~list_title'),
        layout:         'fit',
        items:          [this.list]
    }, config));

    Serum.App.get().eventListener.on('actionchanged',   this.onActionChanged, this);
};

Ext.extend(Serum.Panel.Module.List, Ext.Panel, {

    onActionChanged: function(params) {
        if (Serum.Selector.get().currentModule().listClass() != this.listClass) {
            this.listClass = Serum.Selector.get().currentModule().listClass();  

            this.list.unloadSerumEvents();
            this.list.destroy();
            this.remove(this.list);

            this.list = eval('new ' + this.listClass + '(this)');
            this.add(this.list);
            this.doLayout();
        }

        this.setTitle(this.list.getTitle());
        this.list.onActionChanged();
    }
});